<template>
	<view>
        <scroll-view
        :style="'height:'+height+'px;'"
        	class="list-scroll-content " 
        	scroll-y
        	@scrolltolower="getlist"
          
        
        >
		<uni-collapse accordion="true">
		    <uni-collapse-item :title="item.shop_name" show-animation="true" v-for="item in  list">
                  
                    <!-- 包含图片 -->
                    <uni-list>
                        <uni-list-item v-for=" (user,id) in  item.shop_user" :key="id" :show-arrow="false"   @click="saveuser(user.uid)"  :title="user.nickname" :note="this.key!=Y?'点击转出':' '"      :thumb="user.avatar"></uni-list-item>
                    </uni-list> 

		    </uni-collapse-item>
		 
		</uni-collapse>
        <uni-load-more :status="loadingType"></uni-load-more>
        </scroll-view>
        <view class="">  <lb-picker :list="shoplist" :props="myProps"  ref="picker" @confirm="handleConfirm" ></lb-picker></view>
	</view>
</template>

<script>
    import {getOne ,msg,postOne} from '../../api/publicapi.js'
    import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
    import uniCollapse from '@/components/uni-collapse/uni-collapse.vue'
    import uniCollapseItem from '@/components/uni-collapse-item/uni-collapse-item.vue'
    import uniList from "@/components/uni-list/uni-list.vue"
    import uniListItem from "@/components/uni-list-item/uni-list-item.vue"
    import LbPicker from '@/components/lb-picker'
    export default { 
         components: {uniCollapse,uniCollapseItem,uniLoadMore,uniList,uniListItem,LbPicker},
		data() {
			return {
				list:[], 
                height:0,
                loadingType:'more',
                page:1,
                key:'Y',
                uid:null,
                myProps:{
                    label: 'shop_name',
                    value: 'id',
                  
                },
                shoplist:[]
			}
		},
        onLoad(res) {
            console.log(res.name)
            this.key = res.name
            let that =this
            // that.getaddressdata()
            uni.getSystemInfo({
                success: function (res) {
                    console.log(res)
                        that.height = res.windowHeight
          
                }
            });
                  
          this.getlist()  
          this.getshop()
        },
		methods: {
            
            handleConfirm (item) {
                let tenant = item.item
                let uid = this.uid
                
                uni.showModal({
                     title: '提示',
                    content: '是否将此会员转移到'+tenant.shop_name,
                  
                    success: function (res) {
                           if (res.confirm) {
                             let data ={
                                 uid:uid,
                                 parent_uid:tenant.uid,
                                 tenant_id:tenant.id
                             }
                           
                            postOne('front/owner/puttenantuser',data).then(res=>{
                                    msg(res.message)
                            })
                             
                           } else if (res.cancel) {
                      
                               msg('取消操作')
                           }
                       }
                });
            
            },
			getlist(){
			    if(this.loadingType === 'loading' || this.loadingType === 'noMore' ){
			    	//防止重复加载
			    	return;
			    }
			    
			    this.loadingType = 'loading';
			    getOne('front/owner/minigetTenant',{key:this.key,page:this.page}).then(res=>{
					console.log(res.data);
                        if(res.data.data.length>0){
			               this.page += 1
			               for (var i = 0; i < res.data.data.length; i++) {
			                
			                  this.list.push(res.data.data [i]) 
			               }
			           
			           }
                        if(res.data.per_page*res.data.last_page < res.data.total){
                            this.loadingType = 'more'
                        }else{
                              this.loadingType = 'noMore';
                        }	

			    })
               
			},
            saveuser(uid){
                if(this.key == 'Y')return
                this.uid = uid
                console.log(uid)
                this.$refs.picker.show() 
               
            },
            getshop(){
                getOne('front/owner/gettenant',{type:'mini'}).then(res=>{
                     
                        this.shoplist = res.data
                // console.log(this.shoplist)
                })
            }
           
		}
	}
</script>

<style>

</style>
